$(function() {
	//点击联系人，弹出联系人视图
	$(".jm-client-view-body-left-content-table a").click(function() {
		var contactid = $(this).parent().children("input").val();
		if (contactid != null && contactid != "") {
			$('#client-detail-contact-view-dialog').form('clear');
			$('#client-detail-contact-view-dialog').window('open').panel({
				onLoad : function() {
					$.ajax({
						url : 'find-contact-by-contactid',
						type : 'POST',
						async : false,//改为同步请求
						data : {
							contactid : contactid
						},
						success : function(e) {
							$('#client-view-contact-form input[name=cid]').val(e.clientInfo.cid);
							$('#client-view-contact-form').form('load', e);
						}
					});

				}
			});

		}

	});
	
	//编辑客户信息
	$('#jm-client-view-head-button-right-edit').linkbutton({
		onClick:function(){
			var cid = $('#jm-client-view-head-button-right-cid').linkbutton('options').text;
			$.post("client-detail-find-clientInfo-by-cid",{cid:cid},function(e){
				$("#client-detail-edit-client-dialog").window("open").panel({
					onLoad : function() {
						$("#client-detail-edit-client-form").form('load', e);
					}
				});
			});
		}
	});
	
	//删除
	$('#jm-client-view-head-button-right-del').linkbutton({
		onClick:function(){
			var cid = $('#jm-client-view-head-button-right-cid').linkbutton('options').text;
			if(confirm("亲，您真的要删除吗？")){
				$.post('del-client', {
					cid : cid
				}, function(r) {
					if (r.success) {
						alert("亲，删除成功！");
						window.close();
					} else {
						$.messager.alert("提示", r.messager);
					}
				});
			}
		}
	})
})